package com.study.juc;

import java.util.concurrent.CountDownLatch;

/**
 * @author wanghao
 * @version v1.0
 * @description: 减少计数 CountDownLatch
 * @date 2021/12/28 15:50
 * @change [修改时间] [修改者]@[版本号] [修改内容说明]
 */
public class CountDownLatchDemo {

    public static void main(String[] args) throws InterruptedException {

        // 创建CountDownLatch对象，设置初始值
        CountDownLatch countDownLatch = new CountDownLatch(6);

        for (int i = 1; i <= 6; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+" 号同学离开了教室");

                // 计数 -1
                countDownLatch.countDown();
            },String.valueOf(i)).start();
        }

        //等待
        countDownLatch.await();

        System.out.println(Thread.currentThread().getName()+ " 班长锁门走人了");
    }

}
